<template> 
    <div class="app-container">
        <el-card class="filter-container" shadow="never">
            <div>
                <i class="el-icon-search"></i>
                <span>筛选搜索</span>
                <el-button
                        style="float:right"
                        type="primary"
                        @click="handleSearchList()"
                        size="small">
                    查询
                </el-button>
                <el-button
                        style="float:right;margin-right: 15px"
                        @click="handleResetSearch()"
                        size="small">
                    重置
                </el-button>
            </div>
            <div style="margin-top: 15px">
                <el-form :inline="true" :model="listQuery" size="small" label-width="140px">

                    <el-form-item label="日期类型：">
                        <el-select v-model="listQuery.dateFilteType" class="input-width" placeholder="全部" clearable>
                            <el-option v-for="item in dateTypeOptions"
                                       :key="item.value"
                                       :label="item.label"
                                       :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="时间：">
                        <el-date-picker
                                class="input-width"
                                v-model="listQuery.dateStr"
                                value-format="yyyy-MM-dd"
                                type="date"
                                placeholder="请选择时间">
                        </el-date-picker>
                    </el-form-item>
                </el-form>
            </div>
        </el-card>
        <el-card class="operate-container" shadow="never">
            <i class="el-icon-tickets"></i>
            <span>数据列表</span>
        </el-card>
        <div class="table-container">
            <el-table ref="orderTable"
                      :data="list.financeOrderStatisticList"
                      style="width: 100%;"
                      @selection-change="handleSelectionChange"
                      v-loading="listLoading" border>
                <el-table-column label="时间" width="180" align="center">
                    <template slot-scope="scope">{{scope.row.dateStr}}</template>
                </el-table-column>
                <el-table-column label="支付订单数" width="180" align="center">
                    <template slot-scope="scope">{{scope.row.payOrderNum}}</template>
                </el-table-column>
                <el-table-column label="订单金额" width="120" align="center">
                    <template slot-scope="scope">￥{{scope.row.orderAmount}}</template>
                </el-table-column>
                <el-table-column label="成交用户数" align="center">
                    <template slot-scope="scope">{{scope.row.transactionUserNum}}</template>
                </el-table-column>
                <el-table-column label="退款单数" align="center">
                    <template slot-scope="scope">{{scope.row.refundOrderNum}}</template>
                </el-table-column>
                <el-table-column label="退款金额" width="120" align="center">
                    <template slot-scope="scope">￥{{scope.row.refundAmount}}</template>
                </el-table-column>
                <el-table-column label="支付金额" width="120" align="center">
                    <template slot-scope="scope">￥{{scope.row.payAmount}}</template>
                </el-table-column>
                <el-table-column label="操作" width="150" align="center">
                    <template slot-scope="scope">
                        <el-button
                                size="mini"
                                @click="handleViewOrder(scope.$index, scope.row)">订单明细
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="pagination-container">
            <el-row>
                <span style="margin-right: 600px;margin-top: 60px;">合计：订单金额：¥ {{list.orderStatisticTotalInfo.totalOrderAmount}}，
                    退款金额：¥ {{list.orderStatisticTotalInfo.totalRefundAmount}}， 支付净额： ¥ {{list.orderStatisticTotalInfo.totalPayAmount}}</span>
            </el-row>
            <el-row>
                <br>
            </el-row>
        </div>
    </div>
</template>
<script>
    import {listOrderStatistic} from '@/api/finance/orderStatistic'
    import {formatDate} from '@/utils/date';

    const defaultListQuery = {
        dateFilteType: 0,
        dateStr: null,
    };
    export default {
        name: "orderList",
        components: {},
        data() {
            return {
                listQuery: Object.assign({}, defaultListQuery),
                listLoading: true,
                list: {
                    financeOrderStatisticList: [],
                    orderStatisticTotalInfo: {}
                },
                multipleSelection: [],
                dateTypeOptions: [
                    {
                        label: '本日',
                        value: 0
                    },
                    {
                        label: '本周',
                        value: 1
                    },
                    {
                        label: ' 本月',
                        value: 2
                    }
                ],
            }
        },
        created() {
            this.getList();
        },
        filters: {
            formatCreateTime(time) {
                let date = new Date(time);
                return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
            },
        },
        methods: {
            /**
             * 重置
             */
            handleResetSearch() {
                this.listQuery = Object.assign({}, defaultListQuery);
            },
            /**
             * 搜索
             */
            handleSearchList() {
                this.getList();
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            /**
             * 查看订单明细
             * @param index
             * @param row
             */
            handleViewOrder(index, row) {
                this.$router.push({path: '/oms/order', query: {submitTime: row.dateStr, type: "OrderStatistic"}})
            },
            /**
             * 请求数据列表
             */
            getList() {
                this.listLoading = true;
                listOrderStatistic(this.listQuery).then(response => {
                    this.listLoading = false;
                    this.list = response.data;
                });
            },
        }
    }
</script>
<style scoped>
    .input-width {
        width: 203px;
    }
</style>


